import Vue from 'vue'
// 路由插件
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/layout/home',
  },
  {
    // 一级path有 ‘/’
    path: '/login',
    name: 'login',
    component: () => import('../views/Login.vue'),
  },
  {
    // 一级path有 ‘/’
    path: '/detail/:id',
    name: 'detail',
    component: () => import('../views/Detail.vue'),
  },
  {
    path: '/layout',
    name: 'layout',
    component: () => import('../layouts/index.vue'),
    children: [
      {
        // 二级path没有 ‘/’
        path: 'home',
        name: 'home',
        component: () => import('../views/Home.vue'),
      },
      {
        path: 'classify',
        name: 'classify',
        component: () => import('../views/Classify.vue'),
      },
      {
        path: 'person',
        name: 'person',
        component: () => import('../views/PersonCenter.vue'),
      },
    ],
  },
  {
    path: '*',
    component: () => import('../views/404.vue'),
  },
]

// 实例化
const router = new VueRouter({
  mode: 'history', // 路由模式
  base: process.env.BASE_URL,
  routes,
})

export default router
